package com.example.administrator.myjdlc.ui;

/**
 * Created by Administrator on 2017/3/21.
 */

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.RadioButton;

import com.example.administrator.myjdlc.R;


public class MyRadioButton extends RadioButton {
    private int mDrawableSize;

    public MyRadioButton(Context context) {
        this(context, (AttributeSet)null, 0);
    }

    public MyRadioButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyRadioButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        Drawable drawableLeft = null;
        Drawable drawableTop = null;
        Drawable drawableRight = null;
        Drawable drawableBottom = null;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyRadioButton);
        int n = a.getIndexCount();

        for(int i = 0; i < n; ++i) {
            int attr = a.getIndex(i);
            Log.i("MyRadioButton", "attr:" + attr);
            switch(attr) {
                case 0:
                    this.mDrawableSize = a.getDimensionPixelSize(0, 50);
                    Log.i("MyRadioButton", "mDrawableSize:" + this.mDrawableSize);
                    break;
                case 1:
                    drawableTop = a.getDrawable(attr);
                    break;
                case 2:
                    drawableRight = a.getDrawable(attr);
                    break;
                case 3:
                    drawableBottom = a.getDrawable(attr);
                    break;
                case 4:
                    drawableLeft = a.getDrawable(attr);
            }
        }

        a.recycle();
        this.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, drawableTop, drawableRight, drawableBottom);
    }

    public void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) {
        if(left != null) {
            left.setBounds(0, 0, this.mDrawableSize, this.mDrawableSize);
        }

        if(right != null) {
            right.setBounds(0, 0, this.mDrawableSize, this.mDrawableSize);
        }

        if(top != null) {
            top.setBounds(0, 0, this.mDrawableSize - 23, this.mDrawableSize - 23);
        }

        if(bottom != null) {
            bottom.setBounds(0, 0, this.mDrawableSize, this.mDrawableSize);
        }

        this.setCompoundDrawables(left, top, right, bottom);
    }
}
